import { Store } from '@zh/common-utils/store'

let store = null

const install = (Vue) => {
  if (install.installed) {
    return
  }
  store = new Store(Vue)
  store.registerModule('unitgroups', {
    namespaced: true,
    state: {
      unitGroupList: []
    },
    mutations: {
      SET_UNIT_GROUP_LIST (state, list) {
        if (list !== undefined) {
          state.unitGroupList = list
        } else {
          state.unitGroupList = undefined
        }
      }
    }
  })

  store.registerModule('businesslines', {
    namespaced: true,
    state: {
      businessLineList: []
    },
    mutations: {
      SET_BUSINESS_LINE_LIST (state, list) {
        if (list !== undefined) {
          state.businessLineList = list
        } else {
          state.businessLineList = undefined
        }
      }
    }
  })

  store.registerModule('parentUnits', {
    namespaced: true,
    state: {
      parentUnitList: []
    },
    mutations: {
      SET_PARENT_UNIT_LIST (state, list = []) {
        state.parentUnitList = list
      }
    }
  })
}

export { store }

export default {
  install
}
